The IDL folder watching system monitors folders for changes and invokes a user-defined callback whenever a change occurs. This enables IDL programmers to create a "batch" client that watches a specified "hot folder" and subsequently performs processing when specific conditions have been met (i.e., a file has been added to, modified, or deleted from the folder).
This example monitors the files in the current working directory, and its subdirectories, and prints out which file has changed and how.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Callback
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro MyCallback, obj, data
COMPILE_OPT IDL2
ret = "The file "
ret += data.file
ret += " has been "
if data.added then ret += "added to"
if data.modified then ret += "modified in"
if data.removed then ret += "removed from"
ret += " the working directory. "
ret += strtrim(obj.user_data,2)
PRINT, ret
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MAIN
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
COMPILE_OPT IDL2
; Get working directory
CD, current=c
f = FOLDERWATCH( c, 'MyCallback', user_data="HURRAY!", /RECURSIVE )
end
The example monitors the current working directory (and subdirectories) for all files and prints out what file has changed and how.
The FolderWatch::Init method initializes a FolderWatch object.
Note: Creation of a FolderWatch object automatically starts it.
Obj = FolderWatch.Init( Folder, Callback [, /ADDED] [, /MODIFIED] [, /REMOVED] [, FREQUENCY=value] [/RECURSIVE] [, USER_DATA=variable] )
Returns an object of type FolderWatch.
A required string indicating the path of the folder to monitor.
A required string value specifying the name of the procedure that IDL should invoke when the specified event happens. The Callback is invoked each time a file changes (i.e., there is not just one Callback per time interval that contains an array of all of the changes that occurred, but instead, one per file change).
The callback must have the following signature:
PRO Name , Obj [, data]
|
Value |
Type |
Description |
|---|---|---|
|
Name |
|
Name of the routine. |
|
Obj |
|
A reference to the FolderWatch object. |
|
data |
Structure |
A required IDLFolderWatchInfo structure containing the following fields:
Use to determine which file changed, and how. |
|
|
|
|
Set this optional keyword in order to fire a Callback when a file has been added to the watch folder. If you do not specify ADDED, MODIFIED, or REMOVED, then all are set.
Note: If ADDED is specified, then MODIFIED and REMOVED are unset.
Set this optional keyword in order to fire a Callback when a file has been modified in the watch folder. If you do not specify ADDED, MODIFIED, or REMOVED, then all are set.
Note: If MODIFIED is specified, then ADDED and REMOVED are unset.
Set this optional keyword in order to fire a Callback when a file has been removed from the watch folder. If you do not specify ADDED, MODIFIED, or REMOVED, then all are set.
Note: If REMOVED is specified, then ADDED and MODIFIED are unset.
Set this optional keyword to equal the number of seconds to wait before checking the folder for further changes in the files. Defaults to 1 and is a double-precision number.
Set this optional keyword to monitor all files in a directory and subdirectories. Defaults to no recursion.
Optional data to be delivered to the Callback function. The delivered data will be a copy of the original. If USER_DATA is not supplied then the callback receives !NULL. USER_DATA can be any valid IDL value. Examples of valid IDL values include: a constant, variable, expression, an array, etc.
Use this method to force IDL to check the specified directory for changes.
Note: This does not start or stop a watch process on a folder.
Obj.Check
None.
None.
None.
Use this method to begin watching a folder.
Note: Creation of a FolderWatch object automatically starts it.
Obj.Start
None.
None.
None.
Use this method to stop watching a specified folder.
Obj.Stop
None.
None.
None.
|
8.4 |
Introduced |